<template>
	<view>
		<view id="container"></view>
	</view>
</template>

<script>
	import AMap from '@/untils/map.js'
	import AMaps from '@/untils/maps.js'
	export default {
		data() {
			return {
				title: 'hello',
				provider: '',
				map: null,
				zoom: 13,
				resAmap: null,
				scrollH: 500,
				scrollW: 500,
				initLat: 34.791312, //初始维度
				initLng: 113.657013, //初始经度
				covers: [],
				LlayAroundGroupOpen: true, //l网周边
				latitude: '',
				longitude: ''
			};
		},
		methods: {
			async initAMap() {
				try {
					this.resAmap = await AMaps();
					this.$nextTick(() => {
						var map = new this.resAmap.Map('container', {
							center: [this.latitude, this.longitude],
							zoom: this.zoom
						});
						this.map = map;
						this.resAmap.plugin('AMap.Geolocation', () => {
							var geolocation = new this.resAmap.Geolocation({
								enableHighAccuracy: true, //是否使用高精度定位，默认:true
								timeout: 10000, //超过10秒后停止定位，默认：5s
								buttonPosition: 'RB', //定位按钮的停靠位置
								zoomToAccuracy: true, //定位成功后是否自动调整地图视野到定位点

							});
							map.addControl(geolocation);
							geolocation.getCurrentPosition(function(status, result) {
								if (status == 'complete') {
									onComplete(result)
								} else {
									onError(result)
								}
							});

						});
						//解析定位结果
						var then = this;

						function onComplete(data) {
							console.log(data) // 获取到的定位信息
							then.initLat = data.position.lat;
							then.initLng = data.position.lng;
						}

						function onError(data) {
							console.log(data) // 定位失败的信息
						}
					})
				} catch (e) {
					console.log(e)
				}

			}

		},

		onLoad() {
			uni.getLocation({
				type: 'wgs84',
				geocode: true,
				success: (res) => {
					console.log(res)
					this.latitude = res.latitude;
					this.longitude = res.longitude;
					this.initAMap()
					let location = [this.initLat, this.initLng]
					let StringLocation = location.toString()
					uni.request({
						url: "https://apis.map.qq.com/ws/geocoder/v1/",
						data: {
							location: StringLocation,
							key: "S5MBZ-P5ICU-23BVV-2DO7B-VIKDO-BLBNU",
							get_poi: 1
						},
						success: (res => {
							// this.poisList = res.data.result.pois
							console.log(res.data.result.pois)
						})
					})

				}
			})



		}
	}
</script>

<style lang="scss">
	#container {
		width: 750rpx;
		height: 1200rpx;
	}
</style>
